<template>
	<view class="menu">
		<view class="menu_header">
			Menu
		</view>
		<ul>
			<li v-for="(item,index) in menuList" :key="index" @click.stop="handleDetails(item)">
				<dl>
					<dt v-if="item.imgurls">
						<image :src="item.imgurls.split(',')[0]" mode=""></image>
					</dt>
					<dd>
						<view class="item_header">
							<p>{{item.name}}</p>
							<view class="item_shop">
								<image v-if="item.num>0" src="/static/jian.png" @click.stop="handleJian(item,index)"
									mode=""></image>
								<text v-if="item.num>0">{{item.num}}</text>
								<image src="/static/jia.png" @click.stop="handleJia(item,index)" mode=""></image>
							</view>
						</view>
						<text>{{item.introduce}}</text>
						<view class="price">
							{{item.discount_price}}Egp<text>{{item.origin_price}}Egp</text>
						</view>
						<view class="discount">
							Discount<text>-{{item.discount}}%</text>
						</view>
					</dd>
				</dl>
			</li>
		</ul>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cartList: []
			}
		},
		props: {
			menuList: {
				type: Array,
				default: () => []
			}
		},
		methods: {
			handleJian(item, index) {
				if (item.num <= 0) return;
				item.num--;
				this.menuList[index].num = item.num;
				this.cartList = this.menuList.filter(product => product.num > 0).map(product => ({
					...product
				}));
				uni.setStorageSync('cartList', this.cartList)
				this.$emit('cart', this.cartList)
			},
			handleJia(item, index) {
				item.num++;
				this.menuList[index].num = item.num;
				this.cartList = this.menuList.filter(product => product.num > 0).map(product => ({
					...product
				}));
				uni.setStorageSync('cartList', this.cartList)
				this.$emit('cart', this.cartList)
			},
			handleDetails(item){
				uni.navigateTo({
					url:"/pages/index/product_details?itemid="+item.itemid
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.menu {
		margin-top: 30rpx;

		.menu_header {
			font-family: Manrope, Manrope;
			font-weight: bold;
			font-size: 36rpx;
			color: #1C120D;
		}

		ul {
			li {
				dl {
					display: flex;
					margin-top: 30rpx;

					dt {


						image {
							width: 140rpx;
							height: 140rpx;
							border-radius: 20rpx;
							background-color: #F0F0F0;
						}
					}

					dd {
						flex: 1;
						padding-left: 30rpx;
						width: 76%;

						.item_header {
							display: flex;
							justify-content: space-between;
							align-items: center;

							p {
								font-family: Manrope, Manrope;
								font-weight: bold;
								font-size: 28rpx;
								color: #1C120D;
								max-width: 75%;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;

							}

							.item_shop {
								display: flex;
								align-items: center;

								image {
									width: 40rpx;
									height: 40rpx;
								}

								text {
									font-family: Manrope, Manrope;
									font-weight: bold;
									font-size: 28rpx;
									color: #1C120D;
									margin: 0 20rpx;
								}
							}
						}

						>text {
							font-family: Manrope, Manrope;
							font-weight: 400;
							font-size: 28rpx;
							color: #666666;
							line-height: 36rpx;
							display: block;
							max-width: 75%;
						}

						.price {
							font-family: Manrope, Manrope;
							font-weight: 600;
							font-size: 30rpx;
							color: #000000;
							display: flex;
							align-items: center;

							text {
								font-size: 24rpx;
								color: #999999;
								margin-left: 24rpx;
								text-decoration: line-through;
								font-weight: normal;
								display: inline-block;
							}
						}

						.discount {
							font-family: Manrope, Manrope;
							font-weight: 400;
							font-size: 28rpx;
							color: #444444;
							display: flex;
							align-items: center;

							text {
								font-size: 24rpx;
								color: #FC721A;
								margin-left: 24rpx;
								font-weight: normal;
								display: inline-block;
							}
						}
					}
				}
			}
		}
	}
</style>